﻿using He.DAL;
using He.Model;
using He.Common;

namespace He.BLL
{
    public class webset
    {
        private readonly DAL.webset dao = new DAL.webset();

        /// <summary>
        ///  读取配置文件
        /// </summary>
        /// <param name="configFilePath"></param>
        /// <returns></returns>
        public Model.webset loadConfig(string configFilePath)
        {
            string cacheWebset = "Cache_Webset";
            //从缓存中根据键读取，并使用as转换
            Model.webset setting = CacheHelper.Get(cacheWebset) as Model.webset;
            if (setting == null)
            {
                setting = dao.loadConfig(configFilePath);
                CacheHelper.Add(cacheWebset, setting, configFilePath);
            }

            return setting;
        }

        /// <summary>
        ///  保存配置文件
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="configFilePath"></param>
        /// <returns></returns>
        public Model.webset SaveConfig(Model.webset model, string configFilePath)
        {
            return dao.saveConifg(model, configFilePath);
        }


        public Model.webset SaveConfig(Model.webset model)
        {
            string configFilePath = PathHelper.MapXmlPath("ConfigPath");
            return dao.saveConifg(model, configFilePath);
        }

        /// <summary>
        /// 获取Webset对象信息
        /// </summary>
        /// <returns></returns>
        public Model.webset GetWebset()
        {
            string configFilePath = PathHelper.MapXmlPath("ConfigPath");
            return loadConfig(configFilePath);
        }
    }
}
